package com.example.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * @author xkx
 * @since 2019/4/4 10:56
 * @description
 */
@Slf4j
@Component
public class CustomFactoryPostProcessor implements BeanFactoryPostProcessor {

  @Override
  public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
      throws BeansException {
    log.error("+++++++++++++++++++ CustomFactoryPostProcessor被调用了  ++++ 开始  ++++++++++++++++++");
    String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
    for (String beanDefinitionName:beanDefinitionNames) {
      System.out.println(beanDefinitionName);
      BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName);
      String[] attributeNames = beanDefinition.attributeNames();
      System.out.println(beanDefinition);
    }
    log.error("+++++++++++++++++++ CustomFactoryPostProcessor被调用了 +++++ 结束 +++++++++++++++++");
  }
}
